package colorchooser;


import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JColorChooser;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;

public class ColorPicker extends JFrame{
    private JColorChooser colorChooser;
    
    public ColorPicker(){
    	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	
        JPanel leftPanel = new JPanel();
        leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));
        leftPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
        
        
        //Create a color chooser.
        colorChooser = new JColorChooser();
        leftPanel.add(createPanelForComponent(colorChooser, "JColorChooser"));

        add(leftPanel, BorderLayout.CENTER);
        
    }
    
    public JPanel createPanelForComponent(JComponent comp, String title) {
    	JPanel panel = new JPanel(new BorderLayout());
    	panel.add(comp, BorderLayout.CENTER);
    	if (title != null) {
    		panel.setBorder(BorderFactory.createTitledBorder(title));
    	}
    	return panel;
    }
    

	/**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        //Create and set up the content pane.
        JFrame newContentPane = new ColorPicker();
        //newContentPane.setOpaque(true); //content panes must be opaque
        //frame.setContentPane(newContentPane);

        //Display the window.
        newContentPane.pack();
        newContentPane.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                //Turn off metal's use of bold fonts
	        UIManager.put("swing.boldMetal", Boolean.FALSE);
                createAndShowGUI();
            }
        });
    }

}

